<?php
class Db{
    private $link;
    public function __construct()
    {
        $this->link = new PDO('mysql:host=localhost;dbname=1706a', 'root', 'root');
    }
    public function add($table,$data){
        $name=$data['work'];
        $money=$data['money'];
        $job=$data['job'];
        $age=$data['age'];
        $sql = "insert into $table (work,money,job,age)values ('$name','$money','$job','$age')";
//        echo $sql;die();
        $this->link->exec($sql);
    }
    public function list($table){
        
        $redis = new \Redis();
        $redis=connect('127.0.0.1','6379');
        $arr=$redis->get('mysql');
        $arr=json_decode($arr,true);
        if($arr=='')
        {
            $sql = "select * from $table";//sql语句
            //实例化
        $query = $this->MysqlPdo->query($sql)->fetchAll(2);

        $data=$query->fetchAll(PDO::FETCH_ASSOC);
        //获取值
        $redis->set('mysql',json_encode($arr));
        }
        return $data;
    }
    public function del($id){
        $sql = "delete from works where id='$id'";
//        echo $sql;die();
        $this->link->exec($sql);
    }
    public function upd($table,$id){
        $sql = "select * from $table where id='$id'";
//        echo $sql;die();
        $query = $this->link->query($sql);
        $data=$query->fetchAll(PDO::FETCH_ASSOC);
        return $data;
    }
    public function do_upd($table,$arr){
        
        $name=$arr['work'];
        $id=$arr['id'];
        $address=$arr['address'];
        $money=$arr['money'];
        $job=$arr['job'];
        $sql = "   UPDATE `$table` SET `work`='$name',`address`='$address',`money`='$money',`job`='$job' WHERE id='$id'";

//        echo $sql;die();
        $this->link->exec($sql);
    }
}


?>